using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using Ezio.Model;
using System.Collections;

namespace Ezio.Service
{
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    [XmlSerializerFormat]
    public class InsumosService : BaseService
    {
        [WebInvoke(UriTemplate = "Create", Method = "POST")]
        public bool Create(Insumos Insumo)
        {
            Provider.AddToInsumos(Insumo);
            return Provider.TrySaveChanges();
        }

        [WebInvoke(UriTemplate = "GetAll", Method = "POST")]
        public ArrayList GetAll()
        {
            Ezio.Informes.ReportFactory R = new Informes.ReportFactory();
            R.CreateCicloMinuta(new DateTime(2011, 6, 5), new DateTime(2011, 6, 12), 1, 2);

            return new ArrayList(Provider.Insumos.ToList());
        }

        [WebInvoke(UriTemplate = "GetById", Method = "POST")]
        public Insumos GetById(int Id)
        {
            return Provider.Insumos.First(i => i.IdInsumo == Id);
        }

        [WebInvoke(UriTemplate = "Update", Method = "POST")]
        public bool Update(Insumos Insumo)
        {
            Insumos miInsumo = Provider.Insumos.Where(t => t.IdInsumo == Insumo.IdInsumo).First();
            miInsumo.Copy(Insumo);
            return Provider.TrySaveChanges();
        }

        [WebInvoke(UriTemplate = "Delete", Method = "POST")]
        public bool Delete(int IdInsumo)
        {
            Provider.DeleteObject(Provider.Insumos.Single(t => t.IdInsumo == IdInsumo));
            return Provider.TrySaveChanges();
        }
    }
}